const express = require("express");
// const static = require("./mymodules/static");
const app = express();

const userMsg = [{
  username:"admin",
  password:"123456"
}];

// 静态资源响应的中间件
// app.get("*", static("./abc") );
// app.get("*", express.static("./abc") );

app.use(express.static("./abc") );
app.use(express.urlencoded());

app.post("/register", (req,res)=>{
  console.log(req.body);
  res.send("1");
})

app.get("/login", (req, res, next)=>{
  const {username, password} = req.query;
  let i;
  const flag = userMsg.some((val, idx)=>{
    i = idx;
    return val.username === username;
  })
  if(flag && userMsg[i].password === password){
    res.send("登录成功")
  }else{
    res.send("用户名或密码不对")
  }
})

app.get("*", (req,res,next)=>{
  res.send("404");
})

app.listen(3000, ()=>{
  console.log("服务器开启成功")
})

